FROM php:7.4.19-fpm-alpine3.13

# 修改镜像源
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories

# 安装依赖,核心扩展,pecl扩展,composer工具
RUN apk update && apk add --no-cache --virtual .build-deps \
    $PHPIZE_DEPS \
    curl-dev \
    imagemagick-dev \
    libtool \
    libxml2-dev \
    sqlite-dev \
    libmcrypt-dev \
    freetype-dev \
    libjpeg-turbo-dev \
    libpng-dev \
    curl \
    imagemagick \
    mysql-client \
    php7-bcmath \
    gettext \
    supervisor \
    rabbitmq-c-dev \
    libzip-dev \
    git \
    zip

RUN pecl install \
    # amqp \
    imagick \
    mcrypt

# ADD https://github.com/mlocati/docker-php-extension-installer/releases/latest/download/install-php-extensions /usr/local/bin/

# RUN chmod +x /usr/local/bin/install-php-extensions && sync && \
#     install-php-extensions amqp

RUN docker-php-ext-install \
    zip \
    curl \
    pdo \
    pdo_mysql \
    pdo_sqlite \
    pcntl \
    tokenizer \
    xml \
    bcmath \
    mysqli \
    shmop \
    soap \
    sockets \
    sysvsem \
    xmlrpc \
    -j"$(getconf _NPROCESSORS_ONLN)" iconv \
    && pecl install -o -f redis \
    && rm -rf /tmp/pear

RUN docker-php-ext-enable redis \
    imagick \
    mcrypt

RUN git clone --depth=1 -b v1.10.2 https://github.com/pdezwart/php-amqp.git /tmp/php-amqp && \
    cd /tmp/php-amqp && \
    phpize && ./configure && make && make install && \
    cd .. && rm -rf /tmp/php-amqp/ && \
    echo 'extension=amqp.so' >> /etc/php7/conf.d/amqp.ini

# # Extract PHP source
# RUN apk update && apk add rabbitmq-c-dev \ 
# && docker-php-source extract \
# # Create directory for amqp extension
# && mkdir /usr/src/php/ext/amqp \
# # Download AMQP master branch files to extension directory
# && curl -L https://github.com/php-amqp/php-amqp/archive/master.tar.gz | tar -xzC /usr/src/php/ext/amqp --strip-components=1 \
# # Install amqp extension using built-in docker binary
# && docker-php-ext-install amqp \
# && docker-php-ext-enable amqp \
# Delete PHP source
# && docker-php-source delete

# 设置时区
RUN apk add tzdata && cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \
    && echo "Asia/Shanghai" > /etc/timezone \
    && apk del tzdata

# 安装nginx
RUN apk add --no-cache nginx

WORKDIR /var/www/html

COPY supervisord.conf /etc/supervisord.conf

# 本地安装指定版本composer
COPY composer.phar /usr/local/bin/composer
ENV COMPOSER_ALLOW_SUPERUSER=1
ENV COMPOSER_NO_INTERACTION=1
ENV COMPOSER_HOME=/usr/local/share/composer
RUN chmod +x /usr/local/bin/composer \
&& mkdir -p /usr/local/share/composer

# 对其他容器开放9000端口
EXPOSE 9000

# start php-fpm via supervisor
ENTRYPOINT ["/usr/bin/supervisord", "-n", "-c", "/etc/supervisord.conf"]